s
import java.util.Date;
import java.util.UUID;
import java.text.SimpleDateFormat;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;

// 用户抽象类
abstract class User {
    protected String userId;
    protected String username;
    protected String password;
    protected Date registerTime;
    protected String phone;
    protected String userType;

    public User(String userId, String username, String password, Date registerTime, String phone, String userType) {
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.registerTime = registerTime;
        this.phone = phone;
        this.userType = userType;
    }

    // 抽象方法
    public abstract boolean login(String inputPassword);
    public abstract void logout();
    public abstract void changePassword(String oldPwd, String newPwd) throws Exception;

    // 通用方法
    public void viewPersonalInfo() {
        System.out.println("用户ID: " + userId);
        System.out.println("用户名: " + username);
        System.out.println("注册时间: " + registerTime);
        System.out.println("手机号: " + phone);
        System.out.println("用户类型: " + userType);
    }

    // Getter和Setter
    public String getUserId() { return userId; }
    public String getUsername() { return username; }
    public String getPassword() { return password; }
    public void setPassword(String password) { this.password = password; }
    public Date getRegisterTime() { return registerTime; }
    public String getPhone() { return phone; }
    public String getUserType() { return userType; }
}

// 管理员类
class Admin extends User {
    public Admin(String userId, String username, String password, Date registerTime, String phone) {
        super(userId, username, password, registerTime, phone, "ADMIN");
    }

    @Override
    public boolean login(String inputPassword) {
        return this.password.equals(inputPassword);
    }

    @Override
    public void logout() {
        System.out.println("管理员 " + username + " 已退出系统");
        LogManager.recordLog("退出系统", new Date(), username);
    }

    @Override
    public void changePassword(String oldPwd, String newPwd) throws Exception {
        if (!oldPwd.equals(password)) {
            throw new Exception("原密码错误");
        }
        this.password = newPwd;
        LogManager.recordLog("修改密码", new Date(), username);
    }

    // 管理员特有方法
    public void addUser(User user) {
        UserManager.addUser(user);
        LogManager.recordLog("添加用户: " + user.getUsername(), new Date(), username);
    }

    public void deleteUser(String username) {
        UserManager.deleteUser(username);
        LogManager.recordLog("删除用户: " + username, new Date(), this.username);
    }

    public void listAllUsers() {
        System.out.println("所有用户列表:");
        for (User user : UserManager.getAllUsers()) {
            System.out.println("- " + user.getUsername() + " (" + user.getUserType() + ")");
        }
        LogManager.recordLog("查看用户列表", new Date(), username);
    }
}

// 经理类
class Manager extends User {
    public Manager(String userId, String username, String password, Date registerTime, String phone) {
        super(userId, username, password, registerTime, phone, "MANAGER");
    }

    @Override
    public boolean login(String inputPassword) {
        return this.password.equals(inputPassword);
    }

    @Override
    public void logout() {
        System.out.println("经理 " + username + " 已退出系统");
        LogManager.recordLog("退出系统", new Date(), username);
    }

    @Override
    public void changePassword(String oldPwd, String newPwd) throws Exception {
        if (!oldPwd.equals(password)) {
            throw new Exception("原密码错误");
        }
        this.password = newPwd;
        LogManager.recordLog("修改密码", new Date(), username);
    }

    // 影片管理方法
    public void addMovie(String name, String director, String actors, String introduction, int duration, double rating) {
        Movie movie = new Movie(name, director, actors, introduction, duration, rating);
        MovieManager.addMovie(movie);
        LogManager.recordLog("添加影片: " + name, new Date(), username);
    }

    public void updateMovieRating(String name, double newRating) {
        Movie movie = MovieManager.getMovieByName(name);
        if (movie != null) {
            movie.setRating(newRating);
            LogManager.recordLog("更新影片评分: " + name, new Date(), username);
        }
    }

    // 排片管理方法
    public void addShow(Movie movie, CinemaHall hall, Date showTime, double price) {
        Show show = new Show(movie, hall, showTime, price);
        ShowManager.addShow(show);
        LogManager.recordLog("添加场次: " + movie.getName() + " - " + showTime, new Date(), username);
    }

    public void deleteShow(String showId) {
        ShowManager.deleteShow(showId);
        LogManager.recordLog("删除场次: " + showId, new Date(), username);
    }
}

// 前台类
class Receptionist extends User {
    public Receptionist(String userId, String username, String password, Date registerTime, String phone) {
        super(userId, username, password, registerTime, phone, "RECEPTIONIST");
    }

    @Override
    public boolean login(String inputPassword) {
        return this.password.equals(inputPassword);
    }

    @Override
    public void logout() {
        System.out.println("前台 " + username + " 已退出系统");
        LogManager.recordLog("退出系统", new Date(), username);
    }

    @Override
    public void changePassword(String oldPwd, String newPwd) throws Exception {
        if (!oldPwd.equals(password)) {
            throw new Exception("原密码错误");
        }
        this.password = newPwd;
        LogManager.recordLog("修改密码", new Date(), username);
    }

    // 售票方法
    public Ticket sellTicket(Show show, int[] rowNums, int[] colNums) {
        Seat[] seats = new Seat[rowNums.length];
        for (int i = 0; i < rowNums.length; i++) {
            Seat seat = show.getSeat(rowNums[i], colNums[i]);
            if (seat == null || seat.isSold()) {
                System.out.println("座位不可用: " + rowNums[i] + "排" + colNums[i] + "座");
                return null;
            }
            seats[i] = seat;
        }

        Ticket ticket = TicketSale.sellTicket(show, seats);
        if (ticket != null) {
            LogManager.recordLog("售出票: " + ticket.getTicketId(), new Date(), username);
        }
        return ticket;
    }

    // 退票方法
    public boolean refundTicket(String ticketId) {
        boolean result = TicketRefund.refundTicket(ticketId);
        if (result) {
            LogManager.recordLog("退票: " + ticketId, new Date(), username);
        }
        return result;
    }

    // 显示场次信息
    public void displayShowInfo(Show show) {
        System.out.println("场次信息: " + show.getMovie().getName() + " - " + show.getShowTime());
        System.out.println("放映厅: " + show.getHall().getName());
        System.out.println("票价: " + show.getPrice());
        System.out.println("座位状态:");
        show.displaySeatStatus();
    }
}